﻿package classes 
{
	import classes.*;
	import commands.*;
	import flash.utils.ByteArray;
	
	/**
	 * ...
	 * @author wwx
	 */
	public class ProtocolTranslater 
	{
		
		public function ProtocolTranslater() 
		{
			
		}
		
		public function convertToCmd(cmdType:CommandType, bytes:ByteArray, offset:int, len:int):abCommand
		{
			var cmd:abCommand = null;
			switch(cmdType)
			{
				case CommandType.CMD_TYPE_CREATEROLE_RSP:
				{
				 	var cmdtemp1:CreateRoleCmdRsp = new CreateRoleCmdRsp();
					if (0 == cmdtemp1.convertToCmd(bytes, offset, len))
						cmd = cmdtemp1;
					break;
				}
				case CommandType.CMD_TYPE_GETROOMSOFGAME_RSP:
				{
				 	var cmdtemp1_2_1:GetRoomsOfGameRsp = new GetRoomsOfGameRsp();
					if (0 == cmdtemp1_2_1.convertToCmd(bytes, offset, len))
						cmd = cmdtemp1_2_1;
					break;					
				}
				case CommandType.CMD_TYPE_LOGIN_RSP:
				{
					var cmdtemp2:LoginCmdRsp = new LoginCmdRsp();
					if (0 == cmdtemp2.convertToCmd(bytes, offset, len))
						cmd = cmdtemp2;				
					break;
				}
				case CommandType.CMD_TYPE_LOGOUT_RSP:
				{
					var cmdtemp3:LogoutCmdRsp = new LogoutCmdRsp();
					if (0 == cmdtemp3.convertToCmd(bytes, offset, len))
						cmd = cmdtemp3;	
					break;
				}
				case CommandType.CMD_TYPE_ENTERROOM_RSP:
				{
					var cmdtemp4:EnterRoomCmdRsp = new EnterRoomCmdRsp();
					if (0 == cmdtemp4.convertToCmd(bytes, offset, len))
						cmd = cmdtemp4;				
					break;
				}
				case CommandType.CMD_TYPE_EXITROOM_RSP:
				{
					var cmdtemp5:ExitRoomCmdRsp = new ExitRoomCmdRsp();
					if (0 == cmdtemp5.convertToCmd(bytes, offset, len))
						cmd = cmdtemp5;					
					break;
				}
				case CommandType.CMD_TYPE_SWITCHROOM_RSP:
				{
					var cmdtemp52:SwitchRoomCmdRsp = new SwitchRoomCmdRsp();
					if (0 == cmdtemp52.convertToCmd(bytes, offset, len))
						cmd = cmdtemp52;					
					break;
				}				
				break;
				case CommandType.CMD_TYPE_ENTERDESK_RSP:
				{
					var cmdtemp6:EnterDeskCmdRsp = new EnterDeskCmdRsp();
					if (0 == cmdtemp6.convertToCmd(bytes, offset, len))
						cmd = cmdtemp6;					
					break;
				}
				case CommandType.CMD_TYPE_EXITDESK_RSP:
				{
					var cmdtemp7:ExitDeskCmdRsp = new ExitDeskCmdRsp();
					if (0 == cmdtemp7.convertToCmd(bytes, offset, len))
						cmd = cmdtemp7;					
					break;
				}
				case CommandType.CMD_TYPE_STARTPLAY_RSP:
				{
					var cmdtemp8:StartPlayCmdRsp = new StartPlayCmdRsp();
					if (0 == cmdtemp8.convertToCmd(bytes, offset, len))
						cmd = cmdtemp8;					
					break;
				}
				case CommandType.CMD_TYPE_INJECT_RSP:
				{
					var cmdtemp9:InjectCmdRsp = new InjectCmdRsp();
					if (0 == cmdtemp9.convertToCmd(bytes, offset, len))
						cmd = cmdtemp9;					
					break;
				}
				case CommandType.CMD_TYPE_ADDCHIP_RSP:
				{
					var cmdtemp10:AddChipCmdRsp = new AddChipCmdRsp();
					if (0 == cmdtemp10.convertToCmd(bytes, offset, len))
						cmd = cmdtemp10;					
					break;
				}
				case CommandType.CMD_TYPE_SOHANDLE_RSP:
				{
					var cmdtemp11:SoHandleCmdRsp = new SoHandleCmdRsp();
					if (0 == cmdtemp11.convertToCmd(bytes, offset, len))
						cmd = cmdtemp11;				
					break;
				}
				case CommandType.CMD_TYPE_GIVEUPPLAY_RSP:
				{
					var cmdtemp12:GiveUpPlayCmdRsp = new GiveUpPlayCmdRsp();
					if (0 == cmdtemp12.convertToCmd(bytes, offset, len))
						cmd = cmdtemp12;						
					break;
				}
				case CommandType.CMD_TYPE_FOLLOW_RSP:
				{
					var cmdtemp13:FollowCmdRsp = new FollowCmdRsp();
					if (0 == cmdtemp13.convertToCmd(bytes, offset, len))
						cmd = cmdtemp13;						
					break;
				}
				case CommandType.CMD_TYPE_PASS_RSP:
				{
					var cmdtemp14:PassCmdRsp = new PassCmdRsp();
					if (0 == cmdtemp14.convertToCmd(bytes, offset, len))
						cmd = cmdtemp14;					
					break;
				}
				case CommandType.CMD_TYPE_BRINGCHIPS_RSP:
				{
					var cmdtemp142:BringChipsCmdRsp = new BringChipsCmdRsp();
					if (0 == cmdtemp142.convertToCmd(bytes, offset, len))
						cmd = cmdtemp142;					
					break;
				}				
				case CommandType.CMD_TYPE_RECHARGE_RSP:
				{
					var cmdtemp143:RechargeCmdRsp = new RechargeCmdRsp();
					if (0 == cmdtemp143.convertToCmd(bytes, offset, len))
						cmd = cmdtemp143;					
					break;
				}		
				case CommandType.CMD_TYPE_DESKINOFUPDATE:
				{
					var cmdtemp15:DeskInofUpdateCmd = new DeskInofUpdateCmd();
					if (0 == cmdtemp15.convertToCmd(bytes, offset, len))
						cmd = cmdtemp15;				
					break;
				}
				case CommandType.CMD_TYPE_ASSIGNGOUNDCARD:
				{
					var cmdtemp16:AssignGroundCardCmd = new AssignGroundCardCmd();
					if (0 == cmdtemp16.convertToCmd(bytes, offset, len))
						cmd = cmdtemp16;				
					break;
				}
				case CommandType.CMD_TYPE_ASSIGNPUBLICCARD:
				{
					var cmdtemp17:AssignPublicCardCmd = new AssignPublicCardCmd();
					if (0 == cmdtemp17.convertToCmd(bytes, offset, len))
						cmd = cmdtemp17;	
					break;
				}
				case CommandType.CMD_TYPE_SENDTURNNINGCARD:
				{
					var cmdtemp18:SendTurnningCardCmd = new SendTurnningCardCmd();
					if (0 == cmdtemp18.convertToCmd(bytes, offset, len))
						cmd = cmdtemp18;	
					break;
				}
				case CommandType.CMD_TYPE_SENDRIVERCARD:
				{
					var cmdtemp19:SendRiverCardCmd = new SendRiverCardCmd();
					if (0 == cmdtemp19.convertToCmd(bytes, offset, len))
						cmd = cmdtemp19;				
					break;
				}
				case CommandType.CMD_TYPE_NOTIFYTOCHOOSEOPERATE:
				{
					var cmdtemp20:NotifyToChooseoperateCmd = new NotifyToChooseoperateCmd();
					if (0 == cmdtemp20.convertToCmd(bytes, offset, len))
						cmd = cmdtemp20;	
					break;
				}
				case CommandType.CMD_TYPE_SHOWDOWN:
				{
					var cmdtemp21:ShowDownCmd = new ShowDownCmd();
					if (0 == cmdtemp21.convertToCmd(bytes, offset, len))
						cmd = cmdtemp21;
					break;
				}
				case CommandType.CMD_TYPE_RESULTOFGAME:
				{
					var cmdtemp22:ResultOfGameCmd = new ResultOfGameCmd();
					if (0 == cmdtemp22.convertToCmd(bytes, offset, len))
						cmd = cmdtemp22;
					break;
				}
				case CommandType.CMD_TYPE_PLAYERENTERDESK:
				{
					var cmdtemp23:PlayerEnterDeskCmd = new PlayerEnterDeskCmd();
					if (0 == cmdtemp23.convertToCmd(bytes, offset, len))
						cmd = cmdtemp23;
					break;
				}
				case CommandType.CMD_TYPE_PLAYEREXITDESK:
				{
					var cmdtemp24:PlayerExitDeskCmd = new PlayerExitDeskCmd();
					if (0 == cmdtemp24.convertToCmd(bytes, offset, len))
						cmd = cmdtemp24;
					break;
				}
				case CommandType.CMD_TYPE_POOLINFO:
				{
					var cmdtemp25:PoolInfoCmd = new PoolInfoCmd();
					if (0 == cmdtemp25.convertToCmd(bytes, offset, len))
						cmd = cmdtemp25;				
					break;
				}
				case CommandType.CMD_TYPE_BLINDPOSITION:
				{
					var cmdtemp512:BlindPositionCmd = new BlindPositionCmd();
					if (0 == cmdtemp512.convertToCmd(bytes, offset, len))
						cmd = cmdtemp512;				
					break;
				}
				default:
				break;
			}
			return cmd;
		}
		
		
		public function convertToBytes(cmd:abCommand, bytes:ByteArray, offset:int):int
		{
			var ret:int = 0;
			switch(cmd.getCmdType())
			{
				case CommandType.CMD_TYPE_CREATEROLE_REQ:
				var cmdtemp1:CreateRoleCmdReq  = cmd as CreateRoleCmdReq;
				ret = cmdtemp1.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_GETROOMSOFGAME_REQ:
				var cmdtemp1_2_1:GetRoomsOfGameReq  = cmd as GetRoomsOfGameReq;
				ret = cmdtemp1_2_1.convertToBytes(bytes, offset);					
				break;
				case CommandType.CMD_TYPE_LOGIN_REQ:
				var cmdtemp2:LoginCmdReq  = cmd as LoginCmdReq;
				ret = cmdtemp2.convertToBytes(bytes, offset);				
				break;
				case CommandType.CMD_TYPE_LOGOUT_REQ:
				var cmdtemp3:LogoutCmdReq  = cmd as LogoutCmdReq;
				ret = cmdtemp3.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_ENTERROOM_REQ:
				var cmdtemp4:EnterRoomCmdReq  = cmd as EnterRoomCmdReq;
				ret = cmdtemp4.convertToBytes(bytes, offset);				
				break;
				case CommandType.CMD_TYPE_EXITROOM_REQ:
				var cmdtemp5:ExitRoomCmdReq  = cmd as ExitRoomCmdReq;
				ret = cmdtemp5.convertToBytes(bytes, offset);				
				break;
				case CommandType.CMD_TYPE_SWITCHROOM_REQ:
				var cmdtemp52:SwitchRoomCmdReq  = cmd as SwitchRoomCmdReq;
				ret = cmdtemp52.convertToBytes(bytes, offset);	
				break;
				case CommandType.CMD_TYPE_ENTERDESK_REQ:
				var cmdtemp6:EnterDeskCmdReq  = cmd as EnterDeskCmdReq;
				ret = cmdtemp6.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_EXITDESK_REQ:
				var cmdtemp7:ExitDeskCmdReq  = cmd as ExitDeskCmdReq;
				ret = cmdtemp7.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_STARTPLAY_REQ:
				var cmdtemp8:StartPlayCmdReq  = cmd as StartPlayCmdReq;
				ret = cmdtemp8.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_INJECT_REQ:
				var cmdtemp9:InjectCmdReq  = cmd as InjectCmdReq;
				ret = cmdtemp9.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_ADDCHIP_REQ:
				var cmdtemp:AddChipCmdReq  = cmd as AddChipCmdReq;
				ret = cmdtemp.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_SOHANDLE_REQ:
				var cmdtemp10:SoHandleCmdReq  = cmd as SoHandleCmdReq;
				ret = cmdtemp10.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_GIVEUPPLAY_REQ:
				var cmdtemp11:GiveUpPlayCmdReq  = cmd as GiveUpPlayCmdReq;
				ret = cmdtemp11.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_FOLLOW_REQ:
				var cmdtemp12:FollowCmdReq  = cmd as FollowCmdReq;
				ret = cmdtemp12.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_PASS_REQ:
				var cmdtemp13:PassCmdReq  = cmd as PassCmdReq;
				ret = cmdtemp13.convertToBytes(bytes, offset);
				break;
				case CommandType.CMD_TYPE_BRINGCHIPS_REQ:
				var cmdtemp15:BringChipsCmdReq  = cmd as BringChipsCmdReq;
				ret = cmdtemp15.convertToBytes(bytes, offset);				
				break;
				case CommandType.CMD_TYPE_RECHARGE_REQ:
				var cmdtemp100:RechargeCmdReq  = cmd as RechargeCmdReq;
				ret = cmdtemp100.convertToBytes(bytes, offset);					
				break;
				default:
				break;
			}
			
			return ret;
		}
	}
	
}